package org.corey.share.utils;

import java.util.Map;

import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;

public class CheckCodeTypeConvertor extends DefaultTypeConverter{

	@Override
	public Object convertValue(Map<String, Object> context, Object value,
			Class toType) {
		if (toType == Address.class) {
			String[] params = (String[]) value;
			String str = params[0];
			System.out.println(str);
			String[] infos = str.split(",");
			String city = infos[0];
			String street = infos[1];
			Address address = new Address();
			address.setCity(city);
			address.setStreet(street);
			return address;
		} else if (toType == String.class) {
			Address address = (Address) value;
			if(address!=null){
				return address.getCity() + "." + address.getStreet();
			}
			
		}
		return null;
//		String[] params=(String[])value;
//		String str=params[0];
//		System.out.println(str);
//		String[] infos=str.split(",");
//		String city=infos[0];
//		String street=infos[1];
//		Address address=new Address();
//		address.setCity(city);
//		address.setStreet(street);
//		return address;
	}


}
